package com.ocom.webapi.controller;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ocom.common.HttpUtils;
import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.constant.XFPayUrl;
import com.ocom.common.dto.ConsTypeConfigDto;
import com.ocom.common.dto.Department;
import com.ocom.common.entity.card.*;
import com.ocom.common.entity.human.EntityDeptInfo;
import com.ocom.common.entity.human.EntityPersonnelInfo;
import com.ocom.common.entity.master.EntityFileDownloadInfo;
import com.ocom.common.entity.master.EntityMngUserInfo;
import com.ocom.common.entity.payconfig.EntityXfMerchMoneyDay;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.exposeapi.boczhxy.AuthenticationRequest;
import com.ocom.common.request.exposeapi.boczhxy.TranInfo;
import com.ocom.common.request.payconfig.ConsMerchPayReportsRequest;
import com.ocom.common.request.payconfig.ConsumeDetailErrorRequest;
import com.ocom.common.request.payconfig.TotalTurnoverRequest;
import com.ocom.common.request.payhandle.GzhRechageRefundRequest;
import com.ocom.common.request.payhandle.QrCodeRefundRequest;
import com.ocom.common.request.web.*;
import com.ocom.common.request.xfrecde.*;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.*;
import com.ocom.common.vo.webapi.MealListVo;
import com.ocom.redis.util.RedisUtil;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.*;
import com.ocom.webapi.service.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
@RestController
public class XFPayController {

    @Resource
    private RedisUtil redisUtil;

    @Autowired
    private XfRecordFeign xfRecordFeign;

    @Autowired
    PayConfigClientService payConfigClientService;

    @Autowired
    private HumanClientService humanClientService;

    @Autowired
    private AccessClientService accessClientService;

    @Autowired
    MqSimpleService mqSimpleService;

    @Autowired
    private MqSubsidyClientService maPayClientService;

    @Autowired
    private PayHandleFeignService payHandleFeignService;

    @Autowired
    private ExposeapiFeignService exposeapiFeignService;

    @Autowired
    private CompanyClientService companyClientService;

    @Autowired
    private CompanyService companyService;


    @PostMapping(XFPayUrl.URL_ConsumeDetailOnShow)
    public Result ConsumeDetailOnShow(@RequestBody ConsumeDetailRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());

        String dates = DateUtils.dateTime();

        //限流！
        String ipf = dates+":"+yoCiUser.getId().toString();

        Set<Object> rangeByScore = redisUtil.rangeByScore("consumeDetailOnLimit:"+ipf , System.currentTimeMillis() - 1000l * 60l, System.currentTimeMillis());

        redisUtil.expire("consumeDetailOnLimit:"+ipf,600l);

        if (rangeByScore != null &&  rangeByScore.size() > 19) {
            return ResultUtil.error(ResultEnum.Err_3118);
        }

        redisUtil.zAdd("consumeDetailOnLimit:"+ipf, System.currentTimeMillis() , System.currentTimeMillis());

        if(yoCiUser.getRole()==41l || yoCiUser.getRole()==42l || yoCiUser.getMerchId()>0l){
            List<Long> classIds = yoCiUser.getWxAdmin();
            if(yoCiUser.getWxAdmin()!=null && yoCiUser.getWxAdmin().size()>0 && request.getMerchId()!=null){
                if(!classIds.contains(request.getMerchId().longValue())){
                    request.setMerchId(yoCiUser.getMerchId().intValue());
                }
            }else{
                if(request.getMerchId()==null){
                    request.setMerchIds(String.join(",",classIds.stream().map(x -> x + "").collect(Collectors.toList() )));
                }else{
                    request.setMerchId(yoCiUser.getMerchId().intValue());
                }
            }
        }
        if(yoCiUser.getRole()==23L){
            if(request.getDeptId()==null || !yoCiUser.getWxAdmin().contains(Long.valueOf(yoCiUser.getDeptId()))){
                request.setDeptIds(JSONArray.parseArray(yoCiUser.getWxAdmin().toString(), Integer.class));
            }
        }
        JSONObject jsonObject= JSON.parseObject(JSON.toJSONString(request));
        if (jsonObject.getString("cardNo") != null) {
            Result cardInfoByCardNo = payConfigClientService.getCardInfoByCardNo(yoCiUser.getComId(), jsonObject.getString("cardNo"));
            if (200 == cardInfoByCardNo.getCode() && null != cardInfoByCardNo.getData()) {
                EntityCardInfo entityCardInfo = JSON.parseObject(JSON.toJSONString(cardInfoByCardNo.getData()), EntityCardInfo.class);
                jsonObject.put("pId", entityCardInfo.getPId());
            }else{
                return cardInfoByCardNo;
            }
            jsonObject.remove("cardNo");
        }

        Result result=xfRecordFeign.getConsumeDetail(jsonObject);
        if (result.getCode()==200){
            List<EntityXfMealInfo> listName=new ArrayList<>();
            //查询餐段名称
            Result mealList = payConfigClientService.GetMealNameInfo(request.getComId());
            if(mealList.getCode()==200){
                MealListVo mealListVo = JSON.parseObject(JSON.toJSONString(mealList.getData()),MealListVo.class);
                listName = mealListVo.getList();
            }
            JSONObject reJson=JSON.parseObject(JSON.toJSONString(result.getData()));
            List<EntityXfRecord> list=JSON.parseArray(JSON.toJSONString(reJson.get("list")),EntityXfRecord.class);
            for (EntityXfRecord entityXfRecord : list) {

                if (entityXfRecord.getPId() !=null  && entityXfRecord.getOpType()==22){
                    Result results = humanClientService.GetPersonInfo(request.getComId(),entityXfRecord.getPId());
                    if (results.getCode()==200){
                        if (results.getData() !=null){
                            EntityPersonnelInfo entityPersonnelInfo = JSON.parseObject(JSON.toJSONString(results.getData()), EntityPersonnelInfo.class);
                            if (entityPersonnelInfo.getPPhotoUrl2() !=null){
                                entityXfRecord.setPPhotoUrl2(entityPersonnelInfo.getPPhotoUrl2());
                            }else {
                                entityXfRecord.setPPhotoUrl2(entityPersonnelInfo.getPPhotoUrl());
                            }
                        }
                    }
                }

                entityXfRecord.setSum(entityXfRecord.getRealMoney());
                entityXfRecord.setCharge(entityXfRecord.getChargeMoney());
                entityXfRecord.setSubsidy(entityXfRecord.getSubMoney());
                entityXfRecord.setBalance(entityXfRecord.getChargeBalance()+entityXfRecord.getSubBalance());
                for (EntityXfMealInfo entityXfMealInfo : listName) {
                    if (entityXfRecord.getMealNo().equals(entityXfMealInfo.getMealNo())){
                        entityXfRecord.setMealName(entityXfMealInfo.getMealName());
                    }
                }
                String paymentType= String.valueOf(entityXfRecord.getOpTypeDiff());
                String opType= String.valueOf(entityXfRecord.getOpType());
                int paymentTypes= Integer.parseInt(paymentType);
                entityXfRecord.setAmountType(AcpStateName.getConsName(entityXfRecord.getConsState(),paymentTypes,Integer.parseInt(opType)));
                entityXfRecord.setAmount(entityXfRecord.getConsMoney());
                entityXfRecord.setOrgOrderNo(entityXfRecord.getOrigOrderNo());
                entityXfRecord.setIsRefund(entityXfRecord.getIfRefund());
                entityXfRecord.setChargeBalance(entityXfRecord.getChargeBalance());
                entityXfRecord.setSubBalance(entityXfRecord.getSubBalance());
                entityXfRecord.setAccount(entityXfRecord.getAccountNo());
            }
            reJson.put("list",list);
            return ResultUtil.success(reJson);
        }
        return result;
    }

    @PostMapping(XFPayUrl.URL_ConsumeReportsOnShow)
    public Result consumeReportsOnShow(@RequestBody ConsumeDetailRequest request) {

        String merciless = "";
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        if(yoCiUser.getRole()==41l || yoCiUser.getRole()==42l || yoCiUser.getMerchId()>0l){
            Long merchId = yoCiUser.getMerchId();
            if(yoCiUser.getComId()==74l){
                request.setMerchId(merchId.intValue());
            }else{
                List<Long> merchIds = yoCiUser.getWxAdmin();
                if(request.getMerchId()==null || request.getMerchId()==0){
                    if(merchIds.size()>0){
                        merciless = StringUtils.join(merchIds,",");
                    }
                }else{
                    if(merchIds.size()>0){
                        if(!merchIds.contains(merchId)) {
                            merciless = StringUtils.join(merchIds,",");
                        }else if(!merchId.equals(request.getMerchId().longValue())){
                            merciless = "";
                        }else if(merchId.equals(request.getMerchId().longValue())){
                            merciless = "";
                        }
                    }
                }
            }
        }

        JSONObject jsonObject= JSON.parseObject(JSON.toJSONString(request));
        Result getMealConsumeReports=payConfigClientService.getMealConsumeReports(request.getComId());
        if (getMealConsumeReports.getCode()!=200){
            return getMealConsumeReports;
        }
        jsonObject.put("mealNameInfos",getMealConsumeReports.getData());
        jsonObject.put("merchIds",merciless);
        return xfRecordFeign.getConsumeReports(jsonObject);
    }

    @PostMapping(XFPayUrl.URL_ConsumeReportsOnShowC)
    public Result consumeReportsOnShowC(@RequestBody ConsumeDetailRequest request) {

        String merciless = "";
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        if(yoCiUser.getRole()==41l || yoCiUser.getRole()==42l || yoCiUser.getMerchId()>0l){
            Long merchId = yoCiUser.getMerchId();
            List<Long> merchIds = yoCiUser.getWxAdmin();
            if(request.getMerchId()==null || request.getMerchId()==0){
                if(merchIds.size()>0){
                    merciless = StringUtils.join(merchIds,",");
                }
            }else{
                if(merchIds.size()>0){
                    if(!merchIds.contains(merchId)) {
                        merciless = StringUtils.join(merchIds,",");
                    }else if(!merchId.equals(request.getMerchId().longValue())){
                        merciless = "";
                    }else if(merchId.equals(request.getMerchId().longValue())){
                        merciless = "";
                    }
                }
            }
        }

        JSONObject jsonObject= JSON.parseObject(JSON.toJSONString(request));
        Result getMealConsumeReports=payConfigClientService.getMealConsumeReports(request.getComId());
        if (getMealConsumeReports.getCode()!=200){
            return getMealConsumeReports;
        }
        jsonObject.put("mealNameInfos",getMealConsumeReports.getData());
        jsonObject.put("merchIds",merciless);
        return xfRecordFeign.getConsumeReportsC(jsonObject);
    }

    //3.11.1消费类型列表（ConsTypeConfig/onShow）
    @PostMapping(XFPayUrl.URL_ConsTypeConfigOnShow)
    public Result consTypeConfigOnShow(@RequestBody JSONObject mapComId) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Result consTypeList =  payConfigClientService.getConsType(yoCiUser.getComId());
        Map<String,Object>  map=new HashMap<>();
        if (consTypeList.getCode()==200){
            map.put("consTypeList",consTypeList.getData());
            return ResultUtil.success(map);
        }
        return consTypeList;
    }

    //3.11.3增加消费类型（ConsTypeConfig/new）
    @PostMapping(XFPayUrl.URL_ConsTypeConfigNew)
    public Result consTypeConfigNew(@RequestBody AddConsTypeRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        return payConfigClientService.addConsType(request);
    }

    //4.11修改消费类型参数(setConsType)
    @PostMapping(XFPayUrl.URL_ConsTypeConfigModify)
    public Result consTypeConfigModify(@RequestBody ConsTypeConfigDto entityConsTypeConfig) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        entityConsTypeConfig.setComId(yoCiUser.getComId());
        entityConsTypeConfig.setSubAccount(entityConsTypeConfig.getSubAccountNo());
        entityConsTypeConfig.setConsName(entityConsTypeConfig.getConsTypeName());
        if(null==entityConsTypeConfig.getSubAccount()){
            entityConsTypeConfig.setSubAccount(0);
        }
        return  payConfigClientService.setConsType(entityConsTypeConfig);
    }


    /**
     *@Description:消费账户月统计
     * @author lu 1
     * @param jsonObject
     * @return com.ocom.common.resp.Result
     * @date 2022/10/14 14:00       
     */
    @PostMapping(XFPayUrl.URL_ConsAccSumonShow)
    public Result consAccSumonShow(@RequestBody JSONObject jsonObject) {
        if (jsonObject.get("comId")==null){
            return ResultUtil.error(ResultEnum.Err_203);
        }
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Integer subAccount = jsonObject.getInteger("subAccount");
        if(null==subAccount){
            subAccount= 0;
        }
        Result  result =  xfRecordFeign.walletBalance(yoCiUser.getComId(),jsonObject.getString("month"),subAccount);
        if(result.getCode()!=200){
            return result;
        }
        JSONObject jsonObject1 = JSON.parseObject(JSON.toJSONString(result.getData()));
        jsonObject1.put("merchId" ,yoCiUser.getMerchId() );
        return ResultUtil.success(jsonObject1);
    }


    @PostMapping(WebApiServiceUrl.URL_ConsumeDetailExport)
    public Result ConsumeDetailExport(@RequestBody ConsumeDetailRequest request) {

        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        if(yoCiUser.getRole()==41l || yoCiUser.getRole()==42l || yoCiUser.getMerchId()>0l){
            List<Long> classIds = yoCiUser.getWxAdmin();
            if(yoCiUser.getWxAdmin()!=null && yoCiUser.getWxAdmin().size()>0 && request.getMerchId()!=null){
                if(!classIds.contains(request.getMerchId().longValue())){
                    request.setMerchId(yoCiUser.getMerchId().intValue());
                }
            }else{
                if(request.getMerchId()==null){
                    request.setMerchIds(String.join(",",classIds.stream().map(x -> x + "").collect(Collectors.toList() )));
                }else{
                    request.setMerchId(yoCiUser.getMerchId().intValue());
                }
            }
        }
        if(yoCiUser.getRole()==23L){
            if(request.getDeptId()==null || !yoCiUser.getWxAdmin().contains(Long.valueOf(yoCiUser.getDeptId()))){
                request.setDeptIds(JSONArray.parseArray(yoCiUser.getWxAdmin().toString(), Integer.class));
            }
        }
        JSONObject jsonObject= JSON.parseObject(JSON.toJSONString(request));
        if (jsonObject.getString("cardNo") != null) {
            Result cardInfoByCardNo = payConfigClientService.getCardInfoByCardNo(yoCiUser.getComId(), jsonObject.getString("cardNo"));
            if (200 == cardInfoByCardNo.getCode() && null != cardInfoByCardNo.getData()) {
                EntityCardInfo entityCardInfo = JSON.parseObject(JSON.toJSONString(cardInfoByCardNo.getData()), EntityCardInfo.class);
                jsonObject.put("pId", entityCardInfo.getPId());
            }else{
                return cardInfoByCardNo;
            }
            jsonObject.remove("cardNo");
        }

        int days = differentdaysbymillisecond(DateUtils.strToDate(request.getStartTime()),DateUtils.strToDate(request.getEndTime()));
        if(days>31){
            return ResultUtil.error(ResultEnum.Err_3067);
        }

        if(!request.getStartTime().substring(0,7).equals(request.getEndTime().substring(0,7))){
            return ResultUtil.error(ResultEnum.Err_4138);
        }

        EntityFileDownloadInfo entityFileDownloadInfo =new EntityFileDownloadInfo();
        entityFileDownloadInfo.setPId(yoCiUser.getId());
        entityFileDownloadInfo.setRemark(JSON.toJSONString(request));
        entityFileDownloadInfo.setStatus(0l);
        entityFileDownloadInfo.setName("消费明细报表导出");
        Result result = accessClientService.SendExcelApply(entityFileDownloadInfo);

        if(result.getCode()!=200){
            return ResultUtil.error(ResultEnum.Err_4013);
        }

        request.setId((Integer)result.getData());
        request.setUserId(yoCiUser.getId());
        mqSimpleService.consumeDeatilExport(request);

        return ResultUtil.success();
    }

    public static int differentdaysbymillisecond(Date date1, Date date2)
    {

        int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));

        return days;

    }


    /**
     *@Description:补贴钱包日报表
     * @author lu 
     * @param jsonObject 
     * @return com.ocom.common.resp.Result
     * @date 2022/10/17 15:56       
     */
    @PostMapping(XFPayUrl.URL_ConsAccSumsubsidyDaily)
    public Result consAccSumsubsidyDaily(@RequestBody JSONObject jsonObject) {
        if (jsonObject.get("comId")==null || jsonObject.get("endDate")==null){
            return ResultUtil.error(ResultEnum.Err_203);
        }
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Integer subAccount = jsonObject.getInteger("subAccount");
        if(null==subAccount){
            subAccount=0;
        }
        return  xfRecordFeign.subsidyDaily(yoCiUser.getComId(),jsonObject.getString("endDate"),subAccount);
    }

    /**
     *@Description:现金钱包日报表
     * @author lu 
     * @param jsonObject 
     * @return com.ocom.common.resp.Result
     * @date 2022/10/18 8:48       
     */
    @PostMapping(XFPayUrl.URL_ConsAccSumrechargeDaily)
    public Result consAccSumrechargeDaily(@RequestBody JSONObject jsonObject) {
        if (jsonObject.get("comId")==null || jsonObject.get("endDate")==null){
            return ResultUtil.error(ResultEnum.Err_203);
        }
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Integer subAccount = jsonObject.getInteger("subAccount");
        if(null==subAccount){
            subAccount=0;
        }
        return  xfRecordFeign.rechargeDaily(yoCiUser.getComId(),jsonObject.getString("endDate"),subAccount);
    }

    /**
     *@Description:现金统计
     * @author lu 
     * @param jsonObject
     * @return com.ocom.common.resp.Result
     * @date 2022/10/20 17:15       
     */
    @PostMapping(XFPayUrl.URL_ConsAccSumrecashReport)
    public Result consAccSumrecashReport(@RequestBody JSONObject jsonObject) {
        if (jsonObject.get("comId")==null || jsonObject.get("endDate")==null){
            return ResultUtil.error(ResultEnum.Err_203);
        }
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Integer subAccount = jsonObject.getInteger("subAccount");
        if(null==subAccount){
            subAccount=0;
        }
        String merchIds = "";
        if(yoCiUser.getWxAdmin()!=null && yoCiUser.getWxAdmin().size()>0){
            List<Long>  merchIdsL  = yoCiUser.getWxAdmin();
            merchIds = String.join(", ", merchIdsL.toString().substring(1, merchIdsL.toString().length() - 1).split(","));
        }
        return  xfRecordFeign.cashMonthly(yoCiUser.getComId(),jsonObject.getString("endDate"),subAccount,merchIds);
    }

    /**
     *@Description:现金日报
     * @author lu 
     * @param cashDailyRequest
     * @return com.ocom.common.resp.Result
     * @date 2022/10/21 11:06       
     */
    @PostMapping(XFPayUrl.URL_ConsAccSumrecashDaily)
    public Result consAccSumrecashDaily(@Validated @RequestBody CashDailyRequest cashDailyRequest) {
        if(null==cashDailyRequest.getSubAccount()){
            cashDailyRequest.setSubAccount(0);
        }
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        cashDailyRequest.setComId(yoCiUser.getComId());
        return  xfRecordFeign.cashDaily(cashDailyRequest);
    }

    /**
     *@Description:商户消费统计
     * @author lu 
     * @param jsonObject
     * @return com.ocom.common.resp.Result
     * @date 2022/10/21 14:16       
     */
    @PostMapping(XFPayUrl.URL_ConsAccSummerchantReport)
    public Result consAccSummerchantReport(@RequestBody JSONObject jsonObject) {
        if (jsonObject.get("comId")==null || jsonObject.get("endDate")==null){
            return ResultUtil.error(ResultEnum.Err_203);
        }
        Integer subAccount = jsonObject.getInteger("subAccount");
        if(null==subAccount){
            subAccount=0;
        }
        String merchIds = "";
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        if(yoCiUser.getWxAdmin()!=null && yoCiUser.getWxAdmin().size()>0){
            List<Long>  merchIdsL  = yoCiUser.getWxAdmin();
            merchIds = String.join(", ", merchIdsL.toString().substring(1, merchIdsL.toString().length() - 1).split(","));
        }
        return  xfRecordFeign.merchMonthly(yoCiUser.getComId(),jsonObject.getString("endDate"),subAccount,merchIds);
    }

    /**
     *@Description:商户消费日报
     * @author lu 
     * @param jsonObject 
     * @return com.ocom.common.resp.Result
     * @date 2022/10/21 14:16       
     */
    @PostMapping(XFPayUrl.URL_ConsAccSummerchantDaily)
    public Result consAccSummerchantDaily(@RequestBody JSONObject jsonObject) {
        if (jsonObject.get("comId")==null || jsonObject.get("endDate")==null){
            return ResultUtil.error(ResultEnum.Err_203);
        }
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Integer subAccount = jsonObject.getInteger("subAccount");
        if(null==subAccount){
            subAccount=0;
        }
        return  xfRecordFeign.merchDaily(yoCiUser.getComId(),jsonObject.getString("endDate"),jsonObject.getInteger("merchId"),subAccount);
    }

    @PostMapping(XFPayUrl.URL_TurnoveronShow)
    public Result turnoveronShow(@RequestBody TotalTurnoverRequest totalTurnoverRequest){
        YoCiUser yoCiUser= SecurityUtils.getYoCiUser();
        if (yoCiUser.getRole()==41){
            totalTurnoverRequest.setMerchID(Long.valueOf(yoCiUser.getDeptId()));
        }else {
            totalTurnoverRequest.setMerchID(-1L);
        }
        totalTurnoverRequest.setCompanyID(yoCiUser.getComId());
        return payConfigClientService.getTurnoverReports(totalTurnoverRequest);
    }

  @PostMapping(XFPayUrl.URL_TurnoveronShow_XM)
  public Result turnoveronShowXM(@RequestBody TotalTurnoverRequest totalTurnoverRequest){
    YoCiUser yoCiUser= SecurityUtils.getYoCiUser();
    if (yoCiUser.getRole()==41){
      totalTurnoverRequest.setMerchID(Long.valueOf(yoCiUser.getDeptId()));
    }else {
      totalTurnoverRequest.setMerchID(-1L);
    }
    totalTurnoverRequest.setCompanyID(yoCiUser.getComId());
    return payConfigClientService.getTurnoverReportsXM(totalTurnoverRequest);
  }

    /**
     *@Description:人员消费汇总报表
     * @author lu 
     * @param getConsPerReportsRequest
     * @return com.ocom.common.resp.Result
     * @date 2023/2/17 14:40       
     */
    @PostMapping(XFPayUrl.URL_ConsPerReportsonShow)
    public Result consPerReportsonShow(@Validated @RequestBody GetConsPerReportsRequest getConsPerReportsRequest){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        getConsPerReportsRequest.setComId(yoCiUser.getComId());
        if(23 == yoCiUser.getRole()){
            if(getConsPerReportsRequest.getDeptId().equals("-1")){
                getConsPerReportsRequest.setDeptId(yoCiUser.getDeptId());
            }
        }
        if (!getConsPerReportsRequest.getDeptId().equals("-1")){
            Department department=new Department();
            department.setComId(getConsPerReportsRequest.getComId());
            department.setDeptId(Long.valueOf(getConsPerReportsRequest.getDeptId()));
            department.setShowLevel(0);
            Result bootparentDeptId=humanClientService.getDeptIds(department);
            if (bootparentDeptId.getCode()==200){
                JSONObject bootparentDeptIdObject= JSON.parseObject(JSON.toJSONString(bootparentDeptId.getData()));
                String deptIds="";
                if (bootparentDeptIdObject.getString("deptIds").equals("")){
                    deptIds= String.valueOf(getConsPerReportsRequest.getDeptId());
                }else {
                    deptIds=getConsPerReportsRequest.getDeptId()+","+bootparentDeptIdObject.getString("deptIds");
                }
                getConsPerReportsRequest.setDeptIds(deptIds);
            }else {
                getConsPerReportsRequest.setDeptIds(String.valueOf(getConsPerReportsRequest.getDeptId()));
            }
        }
        if (StringUtils.isEmpty(getConsPerReportsRequest.getDeptIds())){
            getConsPerReportsRequest.setDeptIds("-1");
        }
        return xfRecordFeign.getConsPerReports(getConsPerReportsRequest);
    }

    //人员消费汇总报表导出
    @PostMapping(XFPayUrl.URL_consPerReportsExport)
    public Result consPerReportsExport(@RequestBody GetConsPerReportsRequest getConsPerReportsRequest){
        EntityFileDownloadInfo entityFileDownloadInfo=new EntityFileDownloadInfo();
        YoCiUser yoCiUser= SecurityUtils.getYoCiUser();
        entityFileDownloadInfo.setPId(yoCiUser.getId());
        entityFileDownloadInfo.setName("人员消费汇总报表导出");
        entityFileDownloadInfo.setStatus(0l);
        Result result=accessClientService.SendExcelApply(entityFileDownloadInfo);

        if (!getConsPerReportsRequest.getDeptId().equals("-1")){
            Department department=new Department();
            department.setComId(getConsPerReportsRequest.getComId());
            department.setDeptId(Long.valueOf(getConsPerReportsRequest.getDeptId()));
            department.setShowLevel(0);
            Result bootparentDeptId=humanClientService.getDeptIds(department);
            if (bootparentDeptId.getCode()==200){
                JSONObject bootparentDeptIdObject= JSON.parseObject(JSON.toJSONString(bootparentDeptId.getData()));
                String deptIds="";
                if (bootparentDeptIdObject.getString("deptIds").equals("")){
                    deptIds= String.valueOf(getConsPerReportsRequest.getDeptId());
                }else {
                    deptIds=getConsPerReportsRequest.getDeptId()+","+bootparentDeptIdObject.getString("deptIds");
                }
                getConsPerReportsRequest.setDeptIds(deptIds);
            }else {
                getConsPerReportsRequest.setDeptIds(String.valueOf(getConsPerReportsRequest.getDeptId()));
            }
        }
        if (StringUtils.isEmpty(getConsPerReportsRequest.getDeptIds())){
            getConsPerReportsRequest.setDeptIds("-1");
        }

        if(result.getCode()!=200){
            return ResultUtil.error(ResultEnum.Err_4013);
        }
        getConsPerReportsRequest.setId((Integer)result.getData());
        return maPayClientService.consPerReportsDataExport(getConsPerReportsRequest);
    }

    //部门消费汇总报表
    @PostMapping(XFPayUrl.URL_ConsDeptReportsOnShow)
    public Result consDeptReportsOnShow(@Validated @RequestBody GetConsDeptReportsRequest getConsDeptReportsRequest){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        getConsDeptReportsRequest.setComId(yoCiUser.getComId());
        Boolean isDeptRole = false;
        if(23 == yoCiUser.getRole()){
            if(ObjectUtil.isEmpty(getConsDeptReportsRequest.getDeptId()) || getConsDeptReportsRequest.getDeptId().equals(0L)){
                getConsDeptReportsRequest.setDeptId(Long.valueOf(yoCiUser.getDeptId()));
                isDeptRole = true;
            }
        }
        Result result = humanClientService.getDeptList(getConsDeptReportsRequest.getComId(),getConsDeptReportsRequest.getDeptId(),1);
        if (result.getCode()==200){
            List<EntityDeptInfo> deptInfoList = JSON.parseArray(JSON.toJSONString(result.getData()),EntityDeptInfo.class);
            if(isDeptRole){
                for (int i=0;i<deptInfoList.size();i++){
                    EntityDeptInfo entityDeptInfo = deptInfoList.get(i);
                    if(entityDeptInfo.getDeptId().equals(0L)){
                        deptInfoList.remove(i);
                    }
                }
            }
            getConsDeptReportsRequest.setDeptIds(JSON.toJSONString(deptInfoList));
        }else {
            getConsDeptReportsRequest.setDeptIds("-1");
        }
        return payConfigClientService.getConsDeptList(getConsDeptReportsRequest);
    }

    /**
     *@Description:商户消费汇总报表
     * @author lu 
     * @param getConsMerchReportsRequest
     * @return com.ocom.common.resp.Result
     * @date 2023/3/9 9:04       
     */
    @PostMapping(XFPayUrl.URL_ConsMerchReportsOnShow)
    public Result consMerchReportsOnShow(@Validated @RequestBody GetConsMerchReportsRequest getConsMerchReportsRequest){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        if(yoCiUser.getRole()==41l || yoCiUser.getRole()==42l || yoCiUser.getMerchId()>0l){
            getConsMerchReportsRequest.setMerchId(yoCiUser.getMerchId());
        }
        getConsMerchReportsRequest.setNeedChannel(0);
        getConsMerchReportsRequest.setComId(yoCiUser.getComId());
        return payConfigClientService.getConsMerchReports(getConsMerchReportsRequest);
    }


    @PostMapping(XFPayUrl.URL_ConsumeDetailGoodList)
    public Result consumeDetailGoodList(@RequestBody GetXfGoodListRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        return xfRecordFeign.getXfGoodList(request);
    }

    @PostMapping(XFPayUrl.URL_PointMealPreReportsOnShow)
    public Result pointMealPreReportsOnShow(@Validated @RequestBody GetPointMealPreReportsRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        return payConfigClientService.getPointMealPreReports(request);
    }

    @PostMapping(XFPayUrl.URL_PointMealSendReportsOnShow)
    public Result pointMealSendReportsOnShow(@Validated @RequestBody GetPointMealSendReportsRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        return payConfigClientService.getPointMealSendReports(request);
    }

    @PostMapping(XFPayUrl.URL_PointMealSendReportsOnShowXM)
    public Result pointMealSendReportsOnShowXM(@Validated @RequestBody GetPointMealSendReportsXMRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        return payConfigClientService.getPointMealSendReportsXM(request);
    }

    @PostMapping(XFPayUrl.URL_CheckPwdRefund)
    public Result checkPwdRefund(@Validated @RequestBody CheckPwdRefundRequest request) {
        log.info("平台退款-密码验证请求参数:{}", JSON.toJSONString(request));
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();

        //admin超管不判断角色！！
        if(yoCiUser.getId()!=1l){
            if(yoCiUser.getRole()!=41l && yoCiUser.getRole()!=21l && yoCiUser.getRole()!=42l ){
                return ResultUtil.error(ResultEnum.Err_3202);
            }
        }

        Result<EntityMngUserInfo> result1=companyClientService.GetMngUserInfo(yoCiUser.getUsername());
        if(result1.getCode()!=200){
            throw new InvalidGrantException("用户不存在或者密码错误");
        }
        EntityMngUserInfo entityMngUserInfo= result1.getData();
        if (!entityMngUserInfo.getStatus().equals(0)){
            throw new InvalidGrantException("用户已被禁用");
        }
        BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder();
        String hashPass = request.getPwd()+entityMngUserInfo.getSalt();
        boolean b= bcryptPasswordEncoder.matches(hashPass,entityMngUserInfo.getPassword());
        if(!b){
            throw new InvalidGrantException("用户不存在或者密码错误");
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("comId", yoCiUser.getComId());
        jsonObject.put("orderNo", request.getOrderNo());
        jsonObject.put("consState", 1);
        jsonObject.put("startTime", request.getMonthValue().substring(0,10)+" 00:00:00");
        jsonObject.put("endTime", request.getMonthValue().substring(0,10)+" 23:59:59");
        jsonObject.put("page", 1);
        jsonObject.put("size", 1);

        //2.调用接口3.0微服务-消费配置2.27 getConsumeDetail 获取消费记录信息 ;
        Result result2 = xfRecordFeign.getConsumeDetail(jsonObject);
        JSONObject json = JSONObject.parseObject(JSON.toJSONString(result2.getData()));
        JSONArray list = json.getJSONArray("list");
        EntityXfRecord entityXfRecord = JSON.parseObject(JSON.toJSONString(list.get(0)), EntityXfRecord.class);
//        log.info("消费记录信息返回结果:{}",JSON.toJSONString(entityXfRecord));
        if(entityXfRecord.getIfRefund()==0){
            //发起退款
            QrCodeRefundRequest qrCodeRefundRequest = new QrCodeRefundRequest();
            qrCodeRefundRequest.setCompanyId(yoCiUser.getComId());
            qrCodeRefundRequest.setRefundAmount(Math.abs(Math.toIntExact(entityXfRecord.getRealMoney())));
            qrCodeRefundRequest.setTradeNo("MU"+yoCiUser.getId()+"A"+new SimpleDateFormat("yyyymmddHHmm").format(new Date())+RandomUtil.generateNumber(20));
            qrCodeRefundRequest.setOrigTradeNo(entityXfRecord.getOrderNo());
            qrCodeRefundRequest.setMachNo(entityXfRecord.getDeviceNo());
            return payHandleFeignService.qrCodeRefund(qrCodeRefundRequest);
        }
        return ResultUtil.error(ResultEnum.Err_3203);
    }

    @PostMapping(XFPayUrl.URL_ConsMerchPayReportsOnShow)
    public Result consMerchPayReportsOnShow(@RequestBody ConsMerchPayReportsRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId().intValue());
        return payConfigClientService.getConsMerchPayReports(request);
    }

    @PostMapping(XFPayUrl.URL_ConsMerchPayReportsConfirmTrace)
    public Result confirmTrace(@RequestBody JSONObject jsonObject) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        String password = yoCiUser.getPassword();

        Result result=companyClientService.GetMngUserInfo(yoCiUser.getUsername());
        if(result.getCode()!=200){
            throw new InvalidGrantException("用户不存在或者密码错误");
        }

        EntityMngUserInfo entityMngUserInfo= JSON.parseObject(JSON.toJSONString(result.getData()), EntityMngUserInfo.class);
        if (!entityMngUserInfo.getStatus().equals(0)){
            throw new InvalidGrantException("用户已被禁用");
        }
        BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder();
        String hashPass = jsonObject.getString("pwd")+entityMngUserInfo.getSalt();
        boolean b= bcryptPasswordEncoder.matches(hashPass,entityMngUserInfo.getPassword());
        if(!b){
            throw new InvalidGrantException("用户不存在或者密码错误");
        }



        Long comId = yoCiUser.getComId();
        ConsMerchPayReportsRequest consMerchPayReportsRequest = new ConsMerchPayReportsRequest();
        consMerchPayReportsRequest.setPage(1);
        consMerchPayReportsRequest.setSize(1);
        consMerchPayReportsRequest.setComId(Math.toIntExact(comId));
        consMerchPayReportsRequest.setId(jsonObject.getIntValue("id"));
        Result consMerchPayReports = payConfigClientService.getConsMerchPayReports(consMerchPayReportsRequest);
        if (consMerchPayReports.getCode() != 200 || consMerchPayReports.getData() == null) {
            return ResultUtil.success(ResultEnum.Err_1000);
        }
        JSONObject object = JSONObject.parseObject(JSON.toJSONString(consMerchPayReports.getData()));
        JSONArray list = object.getJSONArray("list");

        for (Object o : list) {
            JSONObject jsonObject1 = (JSONObject)o;
            String jsonString = JSON.toJSONString(jsonObject1);
            EntityXfMerchMoneyDay xfMerchMoneyDay = JSON.parseObject(jsonString, EntityXfMerchMoneyDay.class);
            if (xfMerchMoneyDay.getPayState() == 0 || xfMerchMoneyDay.getPayState() == 2) {
                AuthenticationRequest authenticationRequest = new AuthenticationRequest();
                ArrayList<TranInfo> arrayList = new ArrayList<>();
                TranInfo tranInfo = new TranInfo();
                authenticationRequest.setComId(Math.toIntExact(yoCiUser.getComId()));
                authenticationRequest.setMerNo(xfMerchMoneyDay.getMerchNoOut());
                authenticationRequest.setTraceNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+xfMerchMoneyDay.getMerchNoOut());
                authenticationRequest.setUuid(UUID.randomUUID().toString());
                authenticationRequest.setTranDate(new SimpleDateFormat("yyyyMMdd").format(xfMerchMoneyDay.getPayDate()));//前一天
                tranInfo.setMerNo(xfMerchMoneyDay.getMerchNo());
                tranInfo.setTranAmt(String.valueOf(xfMerchMoneyDay.getNowReceived()));
                arrayList.add(tranInfo);
                authenticationRequest.setTranInfo(arrayList);
                //4.13.3商户分账（boczhxy/confirmTrace）
                result = exposeapiFeignService.confirmTrace(authenticationRequest);
            }

        }
        return result;
    }

    @PostMapping(XFPayUrl.URL_ConsumeDetailOnShowError)
    public Result consumeDetailOnShowError(@RequestBody ConsumeDetailErrorRequest request){
        log.info("消费明细查询异常：{}",request);
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId().intValue());
        Result result = payConfigClientService.getConsumeDetailError(request);
        if(ObjectUtil.isEmpty(result)){
            return ResultUtil.success();
        }
        return result;
    }


    @PostMapping(WebApiServiceUrl.URL_cancelOrder)
    public Result consumeReportsOnShow(@Validated @RequestBody CancelOrderRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        return payConfigClientService.repairPayCancel(request);
    }


    @PostMapping(WebApiServiceUrl.URL_gzhRefund)
    public Result gzhRefund(@Validated @RequestBody GzhRechageRefundRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        request.setTradeNo(DateUtils.getStrDate(new Date(), DateUtils.YYYYMMDDHHMMSS) + RandomUtil.generateNumber(18));
        return payHandleFeignService.gzhRechageRefund(request);
    }


    @PostMapping(WebApiServiceUrl.URL_gzhRefundQuery)
    public Result gzhRefundQuery(@RequestBody JSONObject jsonObject) {
//        String orderNo = "20241008074443771112873145408273";
//        String origOrderNo = "CZ0002e32252382420240913131603";
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();

        Result<EntityXfRecordProcess> xfRecordProcessResult = payHandleFeignService.getOrderInfo(yoCiUser.getComId(),jsonObject.getString("orderNo"));

        Long comId =  yoCiUser.getComId();
        Integer merchId =  0;

        EntityXfMerchPayInfo entityXfMerchPayInfo =new EntityXfMerchPayInfo();
        entityXfMerchPayInfo.setComId(comId);
        entityXfMerchPayInfo.setMerchId(merchId);
        Result<EntityXfMerchPayInfo> merchPayInfoResult = payConfigClientService.getPayInfo(entityXfMerchPayInfo);

        EntityXfMerchPayInfo entiyXfMerchPayInfo = merchPayInfoResult.getData();

        Map<String, Object> retMap = new HashMap<>();
        retMap.put("company_id", entiyXfMerchPayInfo.getCompanyId());
        retMap.put("user_name", entiyXfMerchPayInfo.getUserName());
        retMap.put("password", entiyXfMerchPayInfo.getPassword());
        retMap.put("out_trade_no", xfRecordProcessResult.getData().getOrigOrderNo());
        retMap.put("refund_trade_no", xfRecordProcessResult.getData().getOrderNo());

        String payUrl = companyService.getPayCenterUrl1(comId, entiyXfMerchPayInfo.getCompanyId());
        String json = HttpUtils.postJson(payUrl + "/unifiedmicropay/refundQuery", retMap);
        return  JSON.parseObject(json,Result.class);

    }

    @PostMapping(XFPayUrl.URL_MealPreReportsOnShow)
    public Result mealPreReportsOnShow(@RequestBody GetMealPreReportsXMRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        if(ObjectUtil.isEmpty(request.getMerchId())){
            if(yoCiUser.getRole() == 41 || yoCiUser.getRole() == 42){
                request.setMerchId(yoCiUser.getMerchId().intValue());
            }else{
                request.setMerchId(-1);
            }
        }
        return this.xfRecordFeign.getMealPreReportsXM(request);
    }

    @PostMapping(XFPayUrl.URL_MealSendReportsOnShowXMByOne)
    public Result mealSendReportsOnShowXMByOne(@RequestBody GetMealSendReportsXMByOneRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        if(ObjectUtil.isEmpty(request.getMerchId())){
            if(yoCiUser.getRole() == 41 || yoCiUser.getRole() == 42){
                request.setMerchId(yoCiUser.getMerchId().intValue());
            }else{
                request.setMerchId(-1);
            }
        }
        return this.xfRecordFeign.getMealSendReportsXMByOne(request);
    }

    @PostMapping(XFPayUrl.URL_MealSendReportsOnShowXMByTwo)
    public Result mealSendReportsOnShowXMByTwo(@RequestBody  GetMealSendReportsXMByTwoRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        if(ObjectUtil.isEmpty(request.getMerchId())){
            if(yoCiUser.getRole() == 41 || yoCiUser.getRole() == 42){
                request.setMerchId(yoCiUser.getMerchId().intValue());
            }else{
                request.setMerchId(-1);
            }
        }
        return this.xfRecordFeign.getMealSendReportsXMByTwo(request);
    }

    @PostMapping(XFPayUrl.URL_NotMealRecodeOnShow)
    public Result notMealRecode(@RequestBody NotMealRecodeRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setDeptList(new ArrayList<>());
        request.setComId(yoCiUser.getComId());
        if(ObjectUtil.isNotEmpty(request.getDeptId())){
            Result resultA =  this.humanClientService.getDeptList(yoCiUser.getComId(), request.getDeptId(),0);
            if(ObjectUtil.isNotEmpty(resultA.getData())){
                List<EntityDeptInfo> deptInfoList = JSON.parseArray(JSON.toJSONString(resultA.getData()),EntityDeptInfo.class);
                List<Long> deptList = deptInfoList.stream().map(EntityDeptInfo::getDeptId).collect(Collectors.toList());
                request.setDeptList(deptList);
            }
            log.info(resultA.toString());
        }
        return this.xfRecordFeign.getNotMealRecode(request);
    }



    @PostMapping(XFPayUrl.URL_NotMealExport)
    public Result notMealExport(@RequestBody NotMealRecodeRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setDeptList(new ArrayList<>());
        request.setComId(yoCiUser.getComId());
        EntityFileDownloadInfo entityFileDownloadInfo=new EntityFileDownloadInfo();
        entityFileDownloadInfo.setPId(yoCiUser.getId());
        entityFileDownloadInfo.setName("未就餐报表导出");
        entityFileDownloadInfo.setStatus(0l);
        entityFileDownloadInfo.setRemark(JSON.toJSONString(request));

        if(ObjectUtil.isNotEmpty(request.getDeptId())){
            Result resultA =  this.humanClientService.getDeptList(yoCiUser.getComId(), request.getDeptId(),0);
            if(ObjectUtil.isNotEmpty(resultA.getData())){
                List<EntityDeptInfo> deptInfoList = JSON.parseArray(JSON.toJSONString(resultA.getData()),EntityDeptInfo.class);
                List<Long> deptList = deptInfoList.stream().map(EntityDeptInfo::getDeptId).collect(Collectors.toList());
                request.setDeptList(deptList);
            }
            log.info(resultA.toString());
        }


        Result result=accessClientService.SendExcelApply(entityFileDownloadInfo);
        if(result.getCode()!=200){
            return ResultUtil.error(ResultEnum.Err_4013);
        }
//
        request.setDownloadId(Long.valueOf(result.getData().toString()) );
        mqSimpleService.notMealExport(request);

        return ResultUtil.success();
    }

    @PostMapping(WebApiServiceUrl.URL_getXfUserInfo)
    public Result getXfUserInfo(@RequestBody CommonPidVo requset){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        return humanClientService.getXfUserInfo(yoCiUser.getComId(), requset.getPId());
    }



    @PostMapping(WebApiServiceUrl.URL_payOrderQuery)
    public Result gzhOrderQuery(@RequestBody JSONObject jsonObject) {
//        String orderNo = "20241008074443771112873145408273";
//        String origOrderNo = "CZ0002e32252382420240913131603";
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();

        Result<EntityXfRecordProcess> xfRecordProcessResult = payHandleFeignService.getOrderInfo(yoCiUser.getComId(),jsonObject.getString("orderNo"));

        Long comId =  yoCiUser.getComId();
        Integer merchId =  0;

        EntityXfMerchPayInfo entityXfMerchPayInfo =new EntityXfMerchPayInfo();
        entityXfMerchPayInfo.setComId(comId);
        entityXfMerchPayInfo.setMerchId(merchId);
        Result<EntityXfMerchPayInfo> merchPayInfoResult = payConfigClientService.getPayInfo(entityXfMerchPayInfo);

        EntityXfMerchPayInfo entiyXfMerchPayInfo = merchPayInfoResult.getData();

        Map<String, Object> retMap = new HashMap<>();
        retMap.put("company_id", entiyXfMerchPayInfo.getCompanyId());
        retMap.put("user_name", entiyXfMerchPayInfo.getUserName());
        retMap.put("password", entiyXfMerchPayInfo.getPassword());
        retMap.put("out_trade_no", xfRecordProcessResult.getData().getOrderNo());
        retMap.put("pos_no", "1");

        String payUrl = companyService.getPayCenterUrl1(comId, entiyXfMerchPayInfo.getCompanyId());
        String json = HttpUtils.postJson(payUrl + "/unifiedmicropay/select.do", retMap);
        return  JSON.parseObject(json,Result.class);
    }

}
